<script setup lang="ts">
import {ref,watch} from 'vue';

let text=ref("");

const jinci=["你","我","他"]

let isRed=ref(false)

watch(
  ()=>text.value,
  (nv,ov)=>{
      console.log("ov",ov);
      console.log("nv",nv);


      //数组遍历
      jinci.forEach(s=>{
        if(nv.includes(s)){
          isRed.value=true;
          //substring:剪切字符串
          //let hefa_text=nv.substring(0,nv.length-1);
          //text.value=hefa_text;
         // alert("您的回复中包含了禁词")
        }
      })
})
</script>

<template>
   <input type="text" placeholder="输入" v-model="text" class="yellow":class="{red:isRed}">
</template>

<style scoped>
.yellow{
  background-color: yellow;
}
.red{
  background-color: red;
}
</style>
